package managementnode

import (
	"zstackgo/pkg/core"
	"zstackgo/pkg/core/cloudbus"
	"zstackgo/spring"

	"github.com/meilihao/golib/v2/log"
	"go.uber.org/zap"
)

type ComponentLoaderWebListener struct {
	IsInit bool
	Bus    cloudbus.CloudBus
	Node   ManagementNodeManager
}

func (l *ComponentLoaderWebListener) ContextDestroyed() {
	log.Glog.Warn("web listener issued context destroy event, start stopping process")
	if l.IsInit {
		if err := l.Node.StartNode(); err != nil {
			log.Glog.Error("stop node", zap.Error(err))
		}
	}
}

func (l *ComponentLoaderWebListener) ContextInitialized() {
	if !l.IsInit {
		core.PlatformCreateComponentLoaderFromWebApplicationContext(spring.GlobalApplicationContext)
		l.IsInit = true
	}
}
